#ifndef _LOGIC_STATEMACHINESTATE_H_
#define _LOGIC_STATEMACHINESTATE_H_

#include "PlatformTypes.h"

#define DefaultWaitingPeriod 3

typedef enum UsageModeState
{
    UsageModeState_Init = 0x00,
    UsageModeState_Normal = 0x01,   // Usage mode in normal status
    UsageModeState_Ribbon = 0x02,   // Usage mode in Ribbon status
    UsageModeState_Sleep  = 0x03,
} UsageModeState;
extern void UpdateUsageModeState(UsageModeState newState, UsageModeState* targetState);

typedef enum NormalState
{
    NormalStateLeFrntTurnLamp_Invaild   = 0x00, //normal state invaild
    NormalStateLeFrntTurnLamp_Default   = 0x01, //normal state default
    NormalStateLeFrntTurnLamp_Flicker   = 0x02, //normal state left turn lamp turn on Flicker
    NormalStateLeFrntTurnLamp_Flow      = 0x03, //normal state left turn lamp turn on Flow
    NormalStateLeFrntTurnLamp_DayTime   = 0x04, //normal state left turn lamp turn off, DayTime Lamp turn on
    NormalStateLeFrntTurnLamp_Posn      = 0x05, //normal state left turn lamp turn off, Posn Lamp turn on
    NormalStateLeFrntTurnLamp_DayTimeAndPosBoth_ButDayTime  = 0x06, //normal state left turn lamp turn off, daytime lamp and Posn Lamp both turn on, but now daytime lamp working
    NormalStateLeFrntTurnLamp_DayTimeAndPosBoth_ButPosn     = 0x07, //normal state left turn lamp turn off, daytime lamp and Posn Lamp both turn on, but now posn lamp working
} NormalState;
extern void UpdateNormalState(NormalState newState, NormalState* targetState);

typedef enum RibbonLeTurnLampState
{
    RibbonLeTurnLamp_Invaild = 0x00,
    RibbonLeTurnLamp_Free    = 0x01,
    RibbonLeTurnLamp_Flicker = 0x02,
    RibbonLeTurnLamp_Flow    = 0x03,
} RibbonLeTurnLampState;
extern void UpdateRibbonLeTurnLampState(RibbonLeTurnLampState newState, RibbonLeTurnLampState* targetState);

typedef enum RibbonPosnCtrlState
{
    RibbonPosnCtrlState_Invaild = 0x00,
    RibbonPosnCtrlState_Init    = 0x01,
    RibbonPosnCtrlState_Off     = 0x02,
    RibbonPosnCtrlState_On      = 0x03,
    RibbonPosnCtrlState_Again   = 0x04,
} RibbonPosnCtrlState;
extern void UpdateRibbonPosnCtrlState(RibbonPosnCtrlState newState, RibbonPosnCtrlState* targetState);

typedef enum RibbonPosnEffectShowState
{
    RibbonPosnEffectShowState_Invaild = 0x00,
    RibbonPosnEffectShowState_Default = 0x01,
    RibbonPosnEffectShowState_Unlock  = 0x02,
    RibbonPosnEffectShowState_All     = 0x03,
    RibbonPosnEffectShowState_Lock    = 0x04,
    RibbonPosnEffectShowState_Off     = 0x05,
} RibbonPosnEffectShowState;
extern void UpdateRibbonPosnEffectShowState(RibbonPosnEffectShowState newState, RibbonPosnEffectShowState* targetState);

typedef enum RibbonLobeamCtrlState
{
    RibbonLobeamCtrlState_Invaild = 0x00,
    RibbonLobeamCtrlState_Init    = 0x01,
    RibbonLobeamCtrlState_Off     = 0x02,
    RibbonLobeamCtrlState_On      = 0x03,
    RibbonLobeamCtrlState_Again   = 0x04,
} RibbonLobeamCtrlState;
extern void UpdateRibbonLobeamCtrlState(RibbonLobeamCtrlState newState, RibbonLobeamCtrlState* targetState);

typedef enum RibbonLobeamEffectShowState
{
    RibbonLobeamEffectShowState_Invaild = 0x00,
    RibbonLobeamEffectShowState_Default = 0x01,
    RibbonLobeamEffectShowState_Unlock  = 0x02,
    RibbonLobeamEffectShowState_Lock    = 0x03,
} RibbonLobeamEffectShowState;
extern void UpdateRibbonLobeamEffectShowState(RibbonLobeamEffectShowState newState, RibbonLobeamEffectShowState* targetState);

typedef struct StateMachineBase
{
    void (*Entry)();
    void (*Exit)();
    void (*Excute)();

    uint8_t waitExitCount_; //wait for exit success
} StateMachineBase;
extern bool waitLastStateExitFinish(StateMachineBase* sm);
extern void resetWaitExitCount(StateMachineBase* sm, uint8_t maxCount);

typedef struct FrontLampStateManagement
{
    //Usage mode state
    UsageModeState      usageModeState_;

    //normal state
    NormalState         normalState_;

    //Ribbon state
    //ibbon state, lobeam lamp state
    RibbonLobeamCtrlState ribbonLobeamCtrlState_;
    RibbonLobeamEffectShowState ribbonLobeamEffectShowState_;

} FrontLampStateManagement;

typedef struct TurnLampStateManagement
{
    //Usage mode state
    UsageModeState      usageModeState_;

    //normal state
    NormalState         normalState_;

    //Ribbon state
    //Ribbon state, left turn lamp state
    RibbonLeTurnLampState       ribbonLeTurnLampState_;
    //Ribbon state, posn lamp state
    RibbonPosnCtrlState         ribbonPosnCtrlState_;
    RibbonPosnEffectShowState   ribbonPosnEffectShowState_;

} TurnLampStateManagement;

extern FrontLampStateManagement g_FrontLastState;
extern FrontLampStateManagement g_FrontNewState;

extern TurnLampStateManagement g_TurnLastState;
extern TurnLampStateManagement g_TurnNewState;




#endif
